package health.lm.com.find.fragment;

import android.annotation.SuppressLint;
import android.os.Bundle;
import android.webkit.WebSettings;
import android.webkit.WebView;

import butterknife.BindView;
import health.lm.com.component_base.base.mvp.fragment.XLazyFragment;
import health.lm.com.find.R;
import health.lm.com.find.R2;

/**
 * 商家简介
 */
public class IntroductionFragment extends XLazyFragment {

    @BindView(R2.id.webview)
    WebView webview;

    @Override
    public int getLayoutId() {
        return R.layout.fragment_introduction;
    }

    @Override
    public Object newP() {
        return null;
    }


    @SuppressLint("CheckResult")
    @Override
    public void initData(Bundle savedInstanceState) {
        webview.requestDisallowInterceptTouchEvent(true);
        //WebSettings settings = webview.getSettings();
        //settings.setUseWideViewPort(true);
        //settings.setLoadWithOverviewMode(true);
        //settings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.SINGLE_COLUMN);
        //settings.setTextZoom(200);

        Bundle bundle = getArguments();
        if (bundle != null) {
            String url = bundle.getString("id");
            //详情介绍
            webview.loadDataWithBaseURL(null, getHtmlData(url), "text/html", "UTF-8", null);
//            webview.loadUrl(url);
        }
    }

    /**
     * 富文本适配
     */
    private String getHtmlData(String bodyHTML) {
        String head = "<head>"
                + "<meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0, user-scalable=no\"> "
                + "<style>img{max-width: 100%; width:auto; height:auto;} *{word-break:break-all;word-wrap:break-word;}</style>"
                + "</head>";
        return "<html>" + head + "<body>" + bodyHTML + "</body></html>";
    }


    public static IntroductionFragment getInstance(String id) {
        IntroductionFragment fragment = new IntroductionFragment();
        Bundle args = new Bundle();
        args.putSerializable("id", id);
        fragment.setArguments(args);
        return fragment;
    }

}
